Skip to content

fix(yabeda): Normalize plural Yabeda units to Sentry's singular form#2953

Merged
sl0thentr0py merged 1 commit into
masterfrom
fix/yabeda-unit-normalization
May 13, 2026
Merged

fix(yabeda): Normalize plural Yabeda units to Sentry's singular form#2953
sl0thentr0py merged 1 commit into
masterfrom
fix/yabeda-unit-normalization

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 13, 2026

Description

Normalize plural Yabeda unit symbols (e.g. :seconds, :milliseconds, :bytes) to Sentry's canonical singular form (e.g. "second", "millisecond", "byte") in Sentry::Yabeda::Adapter#unit_for.

Yabeda registers units as plural Ruby symbols, but the Sentry units spec expects singular strings. Previously unit_for just called .to_s, sending unrecognized plural units. This change uses .chomp("s") to strip the trailing "s".

Changes

  • sentry-yabeda/lib/sentry/yabeda/adapter.rb: Replace .to_s with .to_s.chomp("s") and remove the TODO comment
  • sentry-yabeda/spec/sentry/yabeda/adapter_spec.rb: Update existing unit expectations to singular form; add dedicated "unit normalization" test group covering plural→singular, milliseconds, nil, and already-singular cases
  • sentry-yabeda/spec/sentry/yabeda/integration_spec.rb: Update integration spec expectation to "millisecond"

Yabeda plugins declare units as plural Ruby symbols (:seconds,
:milliseconds, :bytes) while Sentry's canonical unit format is
singular (second, millisecond, byte). Without normalization,
distribution metrics with units are stored under the wrong unit
string, causing dashboard queries to return empty results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sdk-maintainer-bot
Copy link
Copy Markdown

This PR has been automatically closed. The referenced issue does not show a discussion between you and a maintainer.

To avoid wasted effort on both sides, please discuss your proposed approach in the issue first and wait for a maintainer to respond before opening a PR.

Please review our contributing guidelines for more details.

# in the Sentry product. See https://develop.sentry.dev/sdk/foundations/state-management/scopes/attributes/#units
def unit_for(metric)
metric.unit&.to_s
metric.unit&.to_s&.chomp("s")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The use of chomp("s") to handle pluralization will incorrectly truncate any custom unit that naturally ends in "s", like :process.
Severity: MEDIUM

Suggested Fix

Instead of unconditionally calling chomp("s"), use a more robust method for singularization, such as a dedicated inflection library. Alternatively, if only handling standard units, use a targeted replacement based on a known list of plural forms rather than a blanket string manipulation.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: sentry-yabeda/lib/sentry/yabeda/adapter.rb#L72

Potential issue: The `unit_for` method unconditionally calls `.chomp("s")` on the string
representation of a metric's unit. This is problematic for custom units whose names
legitimately end in "s", such as `:process` or `:status`. In these cases, the unit will
be incorrectly truncated to `"proces"` or `"statu"` before being sent to Sentry. This
results in a mangled, unrecognized unit in Sentry without raising any error or warning,
leading to silent data corruption for those metrics. Standard Sentry units are
unaffected as they do not end in 's' in their singular form.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right but ok in our case, as we do have a fixed set of units for now imho

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8694506. Configure here.

# in the Sentry product. See https://develop.sentry.dev/sdk/foundations/state-management/scopes/attributes/#units
def unit_for(metric)
metric.unit&.to_s
metric.unit&.to_s&.chomp("s")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naive chomp("s") corrupts abbreviated unit names

Low Severity

Using chomp("s") to normalize units will mangle any unit whose singular/canonical form ends in "s". Abbreviated units like :ms, :ops, or :fps would become "m", "op", or "fp". The test "leaves already-singular units unchanged" uses :second (ending in "d"), so it doesn't actually exercise this risky scenario and gives false confidence in the approach.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8694506. Configure here.

@sl0thentr0py sl0thentr0py merged commit ee6fe35 into master May 13, 2026
237 of 290 checks passed
@sl0thentr0py sl0thentr0py deleted the fix/yabeda-unit-normalization branch May 13, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(yabeda): Normalize plural Yabeda units to Sentry's singular form

2 participants